package com.project.controller.system;

import com.project.controller.BaseController;
import com.project.dto.Result;
import com.project.dto.request.cmd.CmdChangePwd;
import com.project.dto.request.cmd.CmdUser;
import com.project.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Date : 10:24 2020/7/1
 */
@RestController
@Api(tags = "普通用户")
public class UserController extends BaseController {
    @Autowired
    private UserService userService;

    @ApiOperation("修改密码")
    @PostMapping("/user/changePwd")
    public Result changePwd(@RequestBody @Valid CmdChangePwd cmdChangePwd) {
        userService.changePwd(cmdChangePwd.getId(),cmdChangePwd.getOldPassword(), cmdChangePwd.getNewPassword());
        return success("修改成功");
    }

    @ApiOperation("修改个人信息")
    @PostMapping("/user/update")
    public Result update(@RequestBody CmdUser cmdUser) {
        userService.update(cmdUser.getId(),cmdUser.getUsername(),cmdUser.getRealName(),cmdUser.getPhone(),cmdUser.getGrade());
        return success("修改成功");
    }

    /*@ApiOperation("甲骨文学习")
    @GetMapping("/user/exercise")
    public Result update() {
        exerciseService.exercise();
        return success("修改成功");
    }*/


}
